from string import Template
import os
from jinja2 import FileSystemLoader, Environment

path, file = os.path.split(__file__)

folders = [os.path.join(path, 'templates')]

loader = FileSystemLoader(folders)
env = Environment(loader=loader)

def wrap_into_html(js, rs='{}'):
    tree = env.get_template('tree.html')
    return tree.render(js=js, rs=rs)
    
def add_path(path):
    global folders
    global env
    folders.append(path)
    loader = FileSystemLoader(folders)
    env = Environment(loader=loader)
    
def render_template(tmpl, d={}):
    tmpl = env.get_template(tmpl)
    return tmpl.render(**d)
